import useDemoStore from "@/store/yzy/getRoute";
import { storeToRefs } from "pinia";
import getViews from "@/utils/yzy/import";
import router from "@/router";
const route = (data: any) => {
  const arr: any = [];
  if (data && data.length > 0) {
    data.forEach((item: any) => {
      if (item.children && item.children.length > 0) {
        arr.push(...route(item.children));
      } else {
        arr.push({
          path: item.component.slice(1),
          component: getViews(`../../views${item.component}.vue`),
        });
      }
    });
  }
  return arr;
};

const getRoute = () => {
  const store = useDemoStore();
  const { Routes } = storeToRefs(store);
  const a = {
    path: "/home",
    component: getViews("../../views/home.vue"),
    children: [
      ...route(Routes.value),
      {
        path: "Agency/treatInfo",
        component: getViews("../../views/Agency/treatInfo.vue"),
      },
      {
        path: "Agency/treatModify",
        component: getViews("../../views/Agency/treatModify.vue"),
      },
      {
        path: "serve/treatInfo",
        component: getViews("../../views/serve/treatInfo.vue"),
      },
      {
        path: "serve/treatModify",
        component: getViews("../../views/serve/treatModify.vue"),
      },
      {
        path: "ModifyPassword",
        component: getViews("../../views/ModifyPassword.vue"),
      },
      {
        path: "institution/ysxq/:id",
        component: () => import("@/components/doctorDetails.vue"),
      },
      {
        path: "institution/addyx",
        component: () => import("@/components/addDoctor.vue"),
      },
      {
        path: "ResidentParticulars/:id",
        component: () => import("@/views/inhabitant/ResidentParticulars.vue"),
      },
      {
        path: "system/zx/addText",
        component: () => import("@/views/system/zx/AddText.vue"),
      },
      {
        path: "system/zx/EditText",
        component: () => import("@/views/system/zx/EditText.vue"),
      },
      {
        path: "system/yp/addDrug",
        component: () => import("@/views/system/yp/AddDrug.vue"),
      },
      {
        path: "system/yp/EditDrug",
        component: () => import("@/views/system/yp/EditDrug.vue"),
      },
      {
        path: "system/lbt/addBanner",
        component: () => import("@/views/system/lbt/AddBanner.vue"),
      },
      {
        path: "system/lbt/editBanner",
        component: () => import("@/views/system/lbt/EditBanner.vue"),
      },
      {
        path: "system/xtgg/addAnnouncement",
        component: () => import("@/views/system/xtgg/AddAnnouncement.vue"),
      },
      {
        path: "system/xtgg/editAnnouncement",
        component: () => import("@/views/system/xtgg/EditAnnouncement.vue"),
      },
      //
      {
        path: "institution/addOrginazation",
        component: () => import("@/views/institution/Addorganization.vue"),
      },

      {
        path: "institution/editoragnization",
        component: () => import("@/views/institution/OganizationEdit.vue"),
      },
      // 写死的团队页面
      {
        path: "institution/addTeam",
        component: () => import("@/views/institution/AddTeam.vue"),
      },
      // 团队详情页面
      {
        path: "institution/teamDetail",
        component: () => import("@/views/institution/teamDetail.vue"),
      },
    ],
  };

  router.addRoute(a);
};
export default getRoute;
